<template>
  <page-meta :root-font-size="$rootFontSize"></page-meta>
  <view>
    <!--订单确认-->
    <u-navbar
      title="订单确认"
      leftIcon="arrow-left"
      leftIconSize="40"
      leftIconColor="#000000"
      @rightClick="cancelTo()"
      :placeholder="true"
      :autoBack="true"
    >
      <view slot="right" class="text-sm text-dark">取消订单</view>
    </u-navbar>
    <u-loading-page
      :loading="isLoading"
      loading-mode="spinner"
      icon-size="56rpx"
      loading-text="拼命加载中..."
      fontSize="28rpx"
      class="z-50 top-0"
    ></u-loading-page>
    <!--第三方购物账号-->
    <view class="mx-5 mt-5" v-if="info.ingStatus == '3'">
      <view class="bg-white py-2.5 rounded-md bg-box-shadow">
        <view class="mx-4">
          <view class="leading-7 text-sm"
            >第1步 打开{{ info.storeTypeName }}App</view
          >
          <view class="flex justify-between items-center">
            <view class="leading-7 text-sm"
              >核对{{ info.storeTypeName }}登录账号名为：<text
                class="text-primary"
                >{{ info.thirdShoppingAccount }}</text
              ></view
            >
            <view @click="showGuide(1, info.storeType)"
              ><u-icon
                name="question-circle"
                color="#CCCCCC"
                size="36rpx"
              ></u-icon
            ></view>
          </view>
        </view>
      </view>
      <u-checkbox-group v-model="isKnow" class="mt-4" iconSize="28rpx">
        <u-checkbox
          size="32rpx"
          name="know"
          activeColor="#FF3D62"
          shape="circle"
        ></u-checkbox>
        <view class="text-xs" @click="isKnow = isKnow.length ? [] : ['know']">
          我已核对{{
            info.storeTypeName
          }}账号，知晓并同意“账号登错无法获得补贴返款”
        </view>
      </u-checkbox-group>
      <view
        class="w-full rounded-full leading-10 text-base h-10 text-center text-white bg-box-shadow bg-primary mt-10"
        v-if="isKnow.length"
        @click="confirmNext(id)"
        >确认</view
      >
    </view>
    <!--验证商品-->
    <view
      class="mx-5 mt-5"
      v-if="info.ingStatus == '4' || info.ingStatus == '5'"
    >
      <view class="bg-white py-2.5 rounded-md bg-box-shadow">
        <view class="mx-4">
          <view class="leading-7 text-sm"
            >第1步 打开{{ info.storeTypeName }}App</view
          >
          <view class="flex justify-between items-center">
            <view class="leading-7 text-sm"
              >核对{{ info.storeTypeName }}登录账号名为：<text
                class="text-primary"
                >{{ info.thirdShoppingAccount }}</text
              ></view
            >
            <view @click="showGuide(1, info.storeType)"
              ><u-icon
                name="question-circle"
                color="#CCCCCC"
                size="36rpx"
              ></u-icon
            ></view>
          </view>
        </view>
      </view>
      <view class="bg-white py-2.5 rounded-md bg-box-shadow mt-5">
        <view class="mx-4">
          <view class="leading-7 text-sm">第2步 找商品</view>
          <view
            class="flex justify-between mt-1 items-center"
            v-if="info.searchType != '4'"
          >
            <view class="flex items-center"
              ><view class="text-sm"
                >{{
                  info.searchType == '1'
                    ? '搜索关键词'
                    : info.searchType == '2'
                    ? '直播间'
                    : info.searchType == '3'
                    ? '口令链接'
                    : info.searchType == '4'
                    ? '二维码'
                    : '搜索关键词'
                }}：</view
              >
              <view
                class="text-sm text-primary w-48"
                v-if="info.searchType == '1'"
                style="word-wrap: break-word"
                >{{ info.keyword }}</view
              >
              <view
                class="rounded-md w-48 px-2.5 leading-8 overflow-x-auto text-xs"
                v-if="info.searchType != '1'"
                style="border: 1px solid #ddd"
                >{{ info.keyword }}</view
              >
            </view>
            <view class="" @click="copyKeyword"
              ><u-icon name="/static/icons/icon-copy.png" size="36rpx"></u-icon
            ></view>
          </view>
          <view class="flex items-center py-2" v-if="info.searchType == '4'">
            <view class="text-sm">二维码：</view>
            <u-album
              :urls="[info.keyword]"
              keyName="url"
              multipleSize="200rpx"
              shape="circle"
              rowCount="3"
              space="20"
              class="diy-album"
            ></u-album>
            <view class="ml-2 text-primary text-xs"
              >点击放大图片<br />截图保存查找</view
            >
          </view>
          <view class="leading-7 text-sm">找到以下商品：</view>
        </view>
        <view class="mx-4">
          <view class="flex pt-3">
            <view class=""
              ><u--image
                :src="info.productImg"
                width="120rpx"
                height="120rpx"
                radius="6"
              ></u--image
            ></view>
            <view class="ml-3">
              <view class="u-line-1 text-sm leading-6"
                ><text>店铺：</text>{{ info.storeName }}</view
              >
              <view class="leading-10"
                ><text class="text-sm">价格：</text
                ><text class="text-base"
                  >{{ info.orderPrice1 }}~{{ info.orderPrice2 }}</text
                ></view
              >
            </view>
          </view>
        </view>
      </view>
      <view
        v-if="
          info.validStatus == '0' ||
          info.validStatus == '3' ||
          info.validStatus == '2'
        "
      >
        <view class="bg-white py-2.5 rounded-md bg-box-shadow mt-5">
          <view class="mx-4">
            <view class="flex justify-between items-center">
              <view class="text-sm leading-10">第3步 验证商品</view>
              <view @click="showGuide(2, info.storeType)"
                ><u-icon
                  name="question-circle"
                  color="#CCCCCC"
                  size="36rpx"
                ></u-icon
              ></view>
            </view>
          </view>
          <view class="py-2.5 mx-4">
            <view class="flex">
              <view class="w-5/6 relative">
                <u--input
                  placeholder="商品链接/口令"
                  border="none"
                  class="bg-gray w-full h-10 text-sm"
                  style="text-indent: 26rpx"
                  v-model="productLink"
                  @focus="isClose = true"
                ></u--input>
                <u-icon
                  name="close-circle-fill"
                  color="#CCCCCC"
                  size="36rpx"
                  class="absolute right-2 top-2.5"
                  v-if="isClose"
                  @click="(isClose = false), (productLink = '')"
                ></u-icon>
              </view>
              <view
                class="w-1/6 text-sm text-center text-primary leading-10"
                @click="pasteProductLink"
                >验证</view
              >
            </view>
          </view>
        </view>
        <view v-if="info.validStatus == '3'">
          <view class="bg-white py-2.5 rounded-md bg-box-shadow mt-5">
            <view class="mx-4">
              <view class="text-sm">补充店铺名称</view>
            </view>
            <view class="border-b-grayLight mt-2.5"></view>
            <view class="py-2.5 mx-4">
              <view class="flex items-center">
                <view class="text-sm">{{ info.storeName1 }}</view>
                <view class="w-10 mx-3">
                  <input
                    class="bg-gray w-full h-10 text-sm text-center"
                    v-model="validKey"
                  />
                </view>
                <view class="text-sm">{{ info.storeName2 }}</view>
              </view>
            </view>
          </view>
          <view
            class="w-full rounded-full leading-10 text-base h-10 text-center text-white bg-box-shadow bg-primary my-6"
            @click="vaildStore"
            >验证店铺</view
          >
        </view>
      </view>
      <view v-if="info.validStatus == '1'">
        <view
          v-if="isValid"
          class="w-full rounded-full leading-10 text-base h-10 text-center text-white bg-box-shadow bg-light mt-10"
        >
          <u-count-down
            :time="seconds"
            format="ss"
            autoStart
            @change="onChange"
            @finish="continueTo(id)"
          >
            <view class="time">
              <!-- <text class="time__item">{{ timeData.minutes }}&nbsp;分</text> -->
              <text class="time__item"
                >{{ timeData.seconds }}&nbsp;秒后继续下一步</text
              >
            </view>
          </u-count-down>
        </view>
        <view
          v-else
          class="w-full rounded-full leading-10 text-base h-10 text-center text-white bg-box-shadow bg-primary mt-10"
          @click="continueNext"
          >下一步</view
        >
      </view>
    </view>
    <!--提交信息-->
    <view class="mx-5 mt-5" v-if="info.ingStatus == '51'">
      <view class="bg-white py-2.5 rounded-md bg-box-shadow">
        <view class="mx-4">
          <view class="leading-7 text-sm font-bold">先核对 再下单</view>
          <view class="flex justify-between items-center">
            <view class="leading-7 text-sm"
              >{{ info.storeTypeName }}登录账号名：<text class="text-primary">{{
                info.thirdShoppingAccount
              }}</text></view
            >
          </view>
          <view class="flex justify-between items-center">
            <view class="leading-7 text-sm"
              >{{ info.storeTypeName }}收货信息为：<text class=""
                >{{ info.receiverName }} {{ info.receiverAddress }}</text
              ></view
            >
            <view
              class="text-xs text-primary w-10 text-right"
              @click="goBind(info.storeType == '40' ? 1 : 2)"
              >修改</view
            >
          </view>
        </view>
      </view>
      <view class="mt-4" v-if="!isAgree.length">
        <u-checkbox-group v-model="isAgree" iconSize="28rpx">
          <u-checkbox
            size="32rpx"
            name="agree"
            activeColor="#FF3D62"
            shape="circle"
          ></u-checkbox>
          <view
            class="text-xs"
            @click="isAgree = isAgree.length ? [] : ['agree']"
          >
            我已核对，知晓并同意“信息错误无法获得补贴返款”
          </view>
        </u-checkbox-group>
      </view>
      <!--我已知晓-->
      <view v-if="isAgree.length">
        <view class="bg-white py-3 rounded-md bg-box-shadow mt-5">
          <view class="mx-4">
            <view class="flex">
              <view class=""
                ><u--image
                  :src="info.productImg"
                  width="160rpx"
                  height="160rpx"
                  radius="6"
                ></u--image
              ></view>
              <view class="ml-3">
                <view class="u-line-1 text-sm leading-5"
                  >实付满<text class="text-primary">{{ info.orderPrice }}</text
                  >元，补贴{{ info.subsidyPrice }}元</view
                >
                <view class="text-xs leading-5"><text>到手：</text>0.01</view>
                <view class="text-xs leading-5"
                  ><text>规格：</text>任意规格</view
                >
                <view class="text-xs leading-5"
                  ><text>店铺：</text>{{ info.storeName }}</view
                >
              </view>
            </view>
          </view>
        </view>
        <view class="bg-white py-2.5 rounded-md bg-box-shadow mt-5">
          <view class="mx-4">
            <view class="flex justify-between items-center pt-2">
              <view class="text-sm">{{
                info.storeType == 40 ? '支付宝账单' : '订单编号'
              }}</view>
              <view
                @click="showGuide(3, info.storeType)"
                v-if="info.storeType != 40"
                ><u-icon
                  name="question-circle"
                  color="#CCCCCC"
                  size="36rpx"
                ></u-icon
              ></view>
              <view @click="showSwiper()" v-if="info.storeType == 40"
                ><u-icon
                  name="question-circle"
                  color="#CCCCCC"
                  size="36rpx"
                ></u-icon
              ></view>
            </view>
          </view>
          <view class="py-2.5 mx-4">
            <view class="flex items-center">
              <view class="text-sm w-1/4">实付金额</view>
              <u--input
                placeholder="实付金额"
                border="bottom"
                class="w-4/5 h-8 text-sm"
                maxlength="6"
                type="text"
                v-model="form.buyerOrderPrice"
                @blur="handleOrderPrice()"
              ></u--input>
            </view>
            <view class="flex items-center">
              <view class="text-sm w-1/4">订单编号</view>
              <u--input
                :placeholder="
                  info.storeType == 40
                    ? '进入支付宝，字母T开头那串数字'
                    : '订单编号'
                "
                border="bottom"
                class="w-4/5 h-8 text-sm"
                v-model="form.buyerOrderNo"
              ></u--input>
            </view>
          </view>
        </view>
        <view class="bg-white py-2.5 rounded-md bg-box-shadow mt-5">
          <view class="mx-4">
            <view class="text-sm">规则</view>
          </view>
          <view class="border-b-grayLight mt-2.5"></view>
          <view class="py-2.5 mx-4">
            <view class="flex items-center">
              <view class="w-1.5 h-1.5 rounded-full bg-primary mr-2"></view>
              <view class="text-xs leading-7"
                >实付金额低于{{ info.orderPrice }}元，少付的会扣除</view
              >
            </view>
            <view class="flex items-center">
              <view class="w-1.5 h-1.5 rounded-full bg-primary mr-2"></view>
              <view class="text-xs leading-7"
                >实付金额高于{{ info.orderPrice }}元，仍然只补贴{{
                  info.subsidyPrice
                }}元</view
              >
            </view>
            <view class="flex items-center">
              <view class="w-1.5 h-1.5 rounded-full bg-primary mr-2"></view>
              <view class="text-xs leading-7"
                >商品价格差异过大时，请反馈给客服</view
              >
            </view>
            <view class="flex items-center">
              <view class="w-1.5 h-1.5 rounded-full bg-primary mr-2"></view>
              <view class="text-xs leading-7"
                >可使用优惠券红包，但返款以实付金额为准</view
              >
            </view>
            <view class="flex items-center">
              <view class="w-1.5 h-1.5 rounded-full bg-primary mr-2"></view>
              <view class="text-xs leading-7"
                >禁止使用返利App下单，会永久封号</view
              >
            </view>
          </view>
        </view>
        <view
          class="w-full rounded-full leading-10 text-base h-10 text-center text-white bg-box-shadow bg-primary my-6"
          @click="orderSubmit"
          >提交</view
        >
      </view>
      <!--我已知晓-->
    </view>
    <!--取消原因-->
    <u-popup :show="isCancel" @close="isCancel = false" :round="25">
      <view class="mx-5 pb-5">
        <view class="text-center text-base leading-10">请选择取消原因</view>
        <u-radio-group
          v-model="cancelReason"
          :borderBottom="true"
          activeColor="#FF3D62"
          placement="column"
          iconPlacement="right"
          iconSize="20px"
        >
          <u-radio
            @change="radioChange"
            :customStyle="{
              paddingTop: '18px',
              paddingBottom: '18px',
            }"
            v-for="(item, index) in radioList"
            :key="index"
            :label="item.name"
            labelSize="14px"
            labelColor="#333333"
            iconColor="#E5E5E5"
            iconSize="20px"
            size="20px"
            :name="item.id"
          >
          </u-radio>
        </u-radio-group>
        <view class="mt-2.5" v-if="isReason">
          <u--input
            v-model="cancelReasonTxt"
            fontSize="28rpx"
            color="#333333"
            placeholderStyle="color: #999999"
            placeholder="其他原因，请输入..."
            clearable
          >
          </u--input>
        </view>
        <view
          class="w-full rounded-full leading-10 text-base h-10 text-center text-white bg-primary bg-box-shadow mt-5"
          @click="cancelConfirm(id)"
          >确定取消</view
        >
      </view>
    </u-popup>
    <!--教程说明-->
    <u-popup
      :show="isGuide"
      @close="isGuide = false"
      mode="center"
      round="15"
      bgColor="#FFEAED"
    >
      <view class="w-72">
        <view
          class="text-center bg-pink text-white text-base rounded-t-md h-10 leading-10"
          >{{ guideTitle }}</view
        >
        <view class="rounded-b-md">
          <view class="mx-4">
            <view class="pt-5" v-if="guideImageShow">
              <image class="w-full" mode="widthFix" :src="guideImage"></image
            ></view>
            <view class="pt-4" v-if="!guideImageShow">
              <u-swiper
                :list="taobaoOrderList"
                indicator
                indicatorActiveColor="#ff7e8e"
                indicatorInactiveColor="#FFEAED"
                indicatorMode="line"
                width="350"
                height="880"
                circular
                :autoplay="false"
                bgColor="none"
              ></u-swiper>
            </view>
            <view class="mx-14 py-5"
              ><view
                class="w-full rounded-full leading-10 text-base h-10 text-center text-white bg-pink"
                @click="isGuide = false"
                >知道了</view
              ></view
            >
          </view>
        </view>
      </view>
    </u-popup>
    <!--提示说明-->
    <u-modal
      :show="isTip"
      title="温馨提示"
      confirmColor="#FF3D62"
      confirmText="知道了"
      :title-style="{
        'font-size': '34rpx',
        'font-weight': 'bold',
        'line-height': '48rpx',
        color: '#000',
      }"
      @confirm="isTip = false"
    >
      <view class="py-1 text-sm leading-6">{{ myTip }}</view>
    </u-modal>
  </view>
</template>

<script>
import {
  cancelOrder,
  continueOpt,
  continueOptConfirm,
  continueOptNext,
  continueOptSubmit,
  continueOptVaild,
} from '../../services/mine';

export default {
  data() {
    return {
      taobaoOrderList: [
        '/static/images/taobao-order1.png',
        '/static/images/taobao-order2.png',
        '/static/images/taobao-order3.png',
      ],
      guideImageShow: true,
      isTip: false,
      myTip: '',
      isClose: false,
      isAgree: [],
      isKnow: [],
      guideTitle: '默认标题',
      guideImage: '',
      isLoading: true,
      //确认第三方购物账号
      isShow: true,
      isGuide: false,
      info: {
        thirdShoppingAccount: '',
        storeTypeName: '',
        ingStatus: '3',
      },
      id: '',
      //找到商品
      productLink: '',
      validKey: '',
      //提交信息
      form: {
        buyerOrderNo: '',
        buyerOrderPrice: '',
      },
      //倒计时秒数
      seconds: 60000,
      timeData: {},
      isValid: true,
      isCancel: false,
      isReason: false,
      cancelReason: 1,
      cancelReasonTxt: '',
      radioList: [
        {
          id: 1,
          name: '找不到',
          disabled: false,
        },
        {
          id: 2,
          name: '价格不对',
          disabled: false,
        },
        {
          id: 3,
          name: '验证一直失败',
          disabled: false,
        },
        {
          id: 4,
          name: '其他',
          disabled: false,
        },
      ],
    };
  },
  async created() {
    const { id } = this.$Route.query;
    this.id = id;
    this.continueTo(id);
  },
  methods: {
    //绑定淘宝&抖音账号
    async goBind(type) {
      this.$Router.push({
        name: 'account-bind',
        params: {
          mediaType: type,
        },
      });
    },
    //淘宝类型查看商家订单号
    showSwiper() {
      this.guideImageShow = false;
      this.isGuide = true;
      this.guideTitle = '复制商家订单号';
    },
    //显示引导教程
    showGuide(type, mediaType) {
      //if (type == 3 && mediaType == 41) return false;
      this.isGuide = true;
      this.guideImageShow = true;
      if (type == 1 && mediaType == 40) {
        this.guideTitle = '淘宝账号';
        this.guideImage = '/static/images/taobaoAccount.png';
      }
      if (type == 1 && mediaType == 41) {
        this.guideTitle = '抖音号';
        this.guideImage = '/static/images/douyinAccount.png';
      }
      if (type == 2 && mediaType == 40) {
        this.guideTitle = '长按标题，拷贝链接';
        this.guideImage = '/static/images/taobaoLink.png';
      }
      if (type == 2 && mediaType == 41) {
        this.guideTitle = '抖音验证';
        this.guideImage = '/static/images/douyinLink.png';
      }
      if (type == 3 && mediaType == 40) {
        this.guideTitle = '复制商家订单号';
        this.guideImage = '/static/images/taobaoOrder.png';
      }
      if (type == 3 && mediaType == 41) {
        this.guideTitle = '如何查找抖音订单号';
        this.guideImage = '/static/images/douyinOrder.png';
      }
    },
    //取消原因选择
    radioChange(name) {
      if (name == 4) {
        this.isReason = true;
      } else {
        this.isReason = false;
      }
    },
    //取消订单isCancel
    cancelTo() {
      this.isCancel = true;
    },
    //确认取消订单
    async cancelConfirm(id) {
      const { code, data } = await cancelOrder({
        id,
        cancelReason: this.cancelReason,
        cancelReasonTxt: this.cancelReason == 4 ? this.cancelReasonTxt : '',
      });
      if (code != 200) return;
      this.isCancel = false;
      uni.$u.toast('操作成功');
      setTimeout(() => {
        this.$Router.push({
          name: 'order',
          params: {
            searchType: 4,
          },
        });
      }, 800);
    },
    //倒计时组件
    onChange(e) {
      this.timeData = e;
    },
    //订单继续 - 获取订单确认信息
    async continueTo(id) {
      const { code, data } = await continueOpt({ id });
      if (code != 200) return;
      this.isLoading = false;
      this.info = data;
      //倒计时逻辑判断，延迟一秒
      if (data.validStoreTime != null) {
        if (
          parseInt(
            new Date(data.serverTime.replace(/-/g, '/')) -
              new Date(data.validStoreTime.replace(/-/g, '/'))
          ) >= 59000
        ) {
          this.isValid = false;
        } else {
          this.seconds =
            60000 -
            parseInt(
              new Date(data.serverTime.replace(/-/g, '/')) -
                new Date(data.validStoreTime.replace(/-/g, '/'))
            );
          this.isValid = true;
        }
        //console.log(this.seconds);
      }
    },
    //订单继续 - 确认第三方购物账号
    async confirmNext(id) {
      const { code, data } = await continueOptConfirm({ id });
      if (code != 200) return;
      this.continueTo(this.id);
    },
    //设置系统剪贴板的内容
    copyKeyword() {
      uni.setClipboardData({
        data: this.info.keyword,
        success: function () {
          console.log('复制成功');
        },
      });
    },
    //输入商品链接点击验证操作
    pasteProductLink() {
      //console.log(this.productLink.indexOf('https') != -1);
      //当用户输入的内容里没有包含https，验证时提示语‘您粘贴的内容不对’
      if (
        this.productLink.indexOf('https') == -1 &&
        this.info.storeType == '40'
      ) {
        // uni.showToast({
        //   title: '您粘贴的内容不对，请长按淘宝商品标题，拷贝链接，再进行粘贴',
        //   icon: 'none',
        // });
        this.isTip = true;
        this.myTip =
          '您粘贴的内容不对，请长按淘宝商品标题，拷贝链接，再进行粘贴';
        return;
      }
      if (
        this.productLink.indexOf('https') == -1 &&
        this.info.storeType == '41'
      ) {
        // uni.showToast({
        //   title:
        //     '您粘贴的内容不对，请点击抖音商品右上角“分享”按钮，复制链接，再进行粘贴',
        //   icon: 'none',
        // });
        this.isTip = true;
        this.myTip =
          '您粘贴的内容不对，请点击抖音商品右上角“分享”按钮，复制链接，再进行粘贴';
        return;
      }
      if (this.productLink == '') {
        uni.showToast({
          title: '请输入商品链接/口令',
          icon: 'none',
        });
        return;
      }
      this.vaildProduct(this.productLink);
      // var _this = this;
      // uni.getClipboardData({
      //   success: function (res) {
      //     _this.productLink = '';
      //     _this.productLink = res.data;
      //     _this.vaildProduct(res.data);
      //   },
      //   fail: function (res) {
      //     //console.log(res);
      //     uni.showToast({
      //       title: '请先复制商品链接到系统剪贴板~',
      //       icon: 'none',
      //     });
      //   },
      // });
    },
    //验证商品
    async vaildProduct(link) {
      let params = {
        id: this.info.id,
        productId: this.info.productId,
        storeType: this.info.storeType,
        validKey: link,
        validType: '1',
      };
      const { code, data } = await continueOptVaild(params);
      this.continueTo(this.id);
      if (code != 200) return;
    },
    //验证店铺
    async vaildStore() {
      if (this.validKey == '') {
        uni.showToast({
          title: '请补充店铺名称',
          icon: 'none',
        });
        return;
      }
      let params = {
        id: this.info.id,
        productId: this.info.productId,
        storeType: this.info.storeType,
        validKey: this.validKey,
        validType: '2',
      };
      const { code, data } = await continueOptVaild(params);
      if (code != 200) return;
      this.continueTo(this.id);
    },
    //下一步
    async continueNext() {
      let params = {
        id: this.info.id,
        orderType: '0',
      };
      const { code, data } = await continueOptNext(params);
      if (code != 200) return;
      this.continueTo(this.id);
    },
    //处理实付金额输入数值
    handleOrderPrice() {
      //console.log(parseFloat(this.form.buyerOrderPrice.trim()));
      if (parseFloat(this.form.buyerOrderPrice.trim()) > '999.99') {
        uni.showToast({
          title: '最大值只能输入999.99',
          icon: 'none',
        });
        this.form.buyerOrderPrice = '999.99';
      } else if (parseFloat(this.form.buyerOrderPrice.trim()) < 0) {
        uni.showToast({
          title: '实付金额不能为负数',
          icon: 'none',
        });
        this.form.buyerOrderPrice = '';
      }
      if (
        Number(this.info.orderPrice) < 25 &&
        Number(this.info.orderPrice) > 0
      ) {
        if (
          parseFloat(this.form.buyerOrderPrice.trim()) <
            parseFloat(Number(this.info.orderPrice) - 5).toFixed(2) ||
          parseFloat(this.form.buyerOrderPrice.trim()) >
            parseFloat(Number(this.info.orderPrice) + 5).toFixed(2)
        ) {
          this.form.buyerOrderPrice = '';
          this.isTip = true;
          this.myTip = `您输入有误，实付金额范围为${parseFloat(
            Number(this.info.orderPrice) - 5
          ).toFixed(2)}~${parseFloat(Number(this.info.orderPrice) + 5).toFixed(
            2
          )}`;
        }
      }
      if (Number(this.info.orderPrice) > 25) {
        if (
          parseFloat(this.form.buyerOrderPrice.trim()) <
            this.info.orderPrice * 0.8 ||
          parseFloat(this.form.buyerOrderPrice.trim()) >
            this.info.orderPrice * 1.2
        ) {
          this.form.buyerOrderPrice = '';
          this.isTip = true;
          this.myTip = `您输入有误，实付金额范围为${(
            this.info.orderPrice * 0.8
          ).toFixed(2)}~${(this.info.orderPrice * 1.2).toFixed(2)}`;
        }
      }
    },
    //订单提交
    async orderSubmit() {
      this.form.buyerOrderPrice = this.form.buyerOrderPrice
        .trim()
        .toString()
        .replace(/\s+/g, '');
      this.form.buyerOrderPrice = this.form.buyerOrderPrice
        .trim()
        .toString()
        .replace('。', '.');
      if (this.form.buyerOrderNo == '') {
        uni.showToast({
          title: '请填写商家订单号',
          icon: 'none',
        });
        return;
      }
      if (this.info.storeType == '40') {
        //淘宝商家订单号验证规则：T开头，24/25位。
        if (
          parseInt(this.form.buyerOrderNo.trim().slice(1)).toString() == 'NaN'
        ) {
          // uni.showToast({
          //   title:
          //     '您粘贴的内容不对，请到支付宝，账单，复制“商家订单号”，再进行粘贴',
          //   icon: 'none',
          // });
          this.isTip = true;
          this.myTip =
            '您粘贴的内容不对，请到支付宝，账单，复制“商家订单号”，再进行粘贴';
          return;
        }
        if (this.form.buyerOrderNo.trim().charAt(0) != 'T') {
          // uni.showToast({
          //   title:
          //     '您粘贴的内容不对，请到支付宝，账单，复制“商家订单号”，再进行粘贴',
          //   icon: 'none',
          // });
          this.isTip = true;
          this.myTip =
            '您粘贴的内容不对，请到支付宝，账单，复制“商家订单号”，再进行粘贴';
          return;
        }
        if (
          !(
            this.form.buyerOrderNo.trim().length == 24 ||
            this.form.buyerOrderNo.trim().length == 25
          )
        ) {
          // uni.showToast({
          //   title:
          //     '您粘贴的内容不对，请到支付宝，账单，复制“商家订单号”，再进行粘贴',
          //   icon: 'none',
          // });
          this.isTip = true;
          this.myTip =
            '您粘贴的内容不对，请到支付宝，账单，复制“商家订单号”，再进行粘贴';
          return;
        }
      }
      if (this.info.storeType == '41') {
        //抖音商家订单号验证规则：纯数字，19/20位。
        if (parseInt(this.form.buyerOrderNo.trim()).toString() == 'NaN') {
          // uni.showToast({
          //   title:
          //     '您粘贴的内容不对，请到抖音订单详情复制正确的“订单编号”，再进行粘贴',
          //   icon: 'none',
          // });
          this.isTip = true;
          this.myTip =
            '您粘贴的内容不对，请到抖音订单详情复制正确的“订单编号”，再进行粘贴';
          return;
        }
        if (
          !(
            this.form.buyerOrderNo.trim().length == 19 ||
            this.form.buyerOrderNo.trim().length == 20
          )
        ) {
          // uni.showToast({
          //   title:
          //     '您粘贴的内容不对，请到抖音订单详情复制正确的“订单编号”，再进行粘贴',
          //   icon: 'none',
          // });
          this.isTip = true;
          this.myTip =
            '您粘贴的内容不对，请到抖音订单详情复制正确的“订单编号”，再进行粘贴';
          return;
        }
      }
      if (this.form.buyerOrderPrice == '') {
        uni.showToast({
          title: '请填写实付金额',
          icon: 'none',
        });
        return;
      }
      let params = {
        activityType: this.info.activityType,
        buyerOrderNo: this.form.buyerOrderNo,
        buyerOrderPrice: this.form.buyerOrderPrice,
        id: this.id,
        orderPrice: this.info.orderPrice,
        thirdPlatformType: this.info.storeType,
      };
      const { code, data, msg } = await continueOptSubmit(params);
      //隐藏消息提示框
      uni.hideToast();
      this.isTip = true;
      this.myTip = msg;
      if (code != 200) return;
      setTimeout(() => {
        this.$Router.push({
          name: 'order',
          params: {
            searchType: 2,
          },
        });
      }, 800);
    },
  },
};
</script>

<style>
page {
  background: #f2f2f2;
}
</style>
